<template>
  <div class="layout">
    <div class="helpHumanDetail">
      <div
        style="display: flex; justify-content: space-between; margin-top: 20px"
      >
        <Breadcrumb class="breadcrumb" :crumbs="crumbs"></Breadcrumb>
      </div>
      <!-- <div class="topDiv">
        <div class="msgDiv">{{ human.name + "-" + human.skill }}</div>
      </div> -->
      <ContainerTitle text="人员简介" :more="false"></ContainerTitle>
      <div class="tableDiv" v-loading="loading">
        <div class="rowDiv">
          <div style="width: 50%; display: flex; justify-content: left">
            <div class="keyDiv">姓名</div>
            <div class="valueDiv">{{ human.name }}</div>
          </div>
          <div style="width: 50%; display: flex; justify-content: left">
            <div class="keyDiv">年龄</div>
            <div class="valueDiv">{{ human.age }}</div>
          </div>
        </div>
        <div class="rowDiv">
          <div style="width: 50%; display: flex; justify-content: left">
            <div class="keyDiv">性别</div>
            <div class="valueDiv" v-if="(genderLsit && genderLsit.length>0) && human.gender">
              {{ $selectDict(genderLsit,human.gender).dictLabel }}
            </div>
          </div>
          <div style="width: 50%; display: flex; justify-content: left">
            <div class="keyDiv">学历</div>
            <div class="valueDiv" v-if="(workerEducationLsit && workerEducationLsit.length>0) && human.education">
              {{ $selectDict(workerEducationLsit,human.education).dictLabel }}
            </div>
          </div>
        </div>
        <div class="rowDiv" v-if="human.status ==2">
          <div style=" width: 50%; display: flex; justify-content: left">
            <div class="keyDiv">职业技能</div>
            <div class="valueDivFull">{{ human.skill }}</div>
          </div>
          <div style="width: 50%;display: flex; justify-content: left">
            <div class="keyDiv">联系电话</div>
            <div class="valueDivFull">{{ human.contact }}</div>
          </div>
        </div>
        <div class="rowDiv" v-else>
          <div style=" display: flex; justify-content: left">
            <div class="keyDiv">职业技能</div>
            <div class="valueDivFull">{{ human.skill }}</div>
          </div>
        </div>
      </div>
      <!-- <div class="title">工作经验描述</div>
      <div class="tableDiv desc">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{
          human.experienceDesc ? human.experienceDesc : "无"
        }}
      </div> -->
       <template v-if="human.status ==2">
        <div class="title">工作经验</div>
        <div v-if="experience.length > 0" v-loading="loading">
          <div class="tableDiv" v-for="(experience, index) in experience" :key="index">
              <div class="rowDiv">
                  <div style="width: 50%; display: flex; justify-content: left">
                      <div class="keyDiv">公司名称</div>
                      <div class="valueDiv">{{ experience.companyName }}</div>
                  </div>
                  <div style="width: 50%; display: flex; justify-content: left">
                      <div class="keyDiv">工作时间</div>
                      <div class="valueDiv" v-if="experience.beginDate"> {{ new Date( experience.beginDate).pattern("yyyy-MM-dd") }} 至 {{ new Date( experience.endDate).pattern("yyyy-MM-dd") }} </div>
                      <div class="valueDiv" v-else>无</div>
                  </div>
              </div>
              <div class="rowDiv">
                  <div style="width: 50%; display: flex; justify-content: left">
                      <div class="keyDiv">部门</div>
                      <div class="valueDiv">{{ experience.dept }}</div>
                  </div>
                  <div style="width: 50%; display: flex; justify-content: left">
                      <div class="keyDiv">职位</div>
                      <div class="valueDiv">{{ experience.post }}</div>
                  </div>
              </div>
              <div class="rowDiv">
                  <div style="display: flex; justify-content: left">
                      <div class="keyDiv">工作内容</div>
                      <div class="valueDivFull">{{ experience.workContent }}</div>
                  </div>
              </div>
          </div>
        </div>
        <div v-else>暂无工作经验数据</div>
      </template>
      <ContainerTitle text="人才推介" :more="false"></ContainerTitle>
      <div class="promotion-box">
        <div class="item" v-for="(item, index) in promotionList" :key="index" @click="toDetail(item,index)">
            <div class="it-left">
                <div class="p1">
                  <p class="t1">·姓名：</p>
                  <p class="tex">{{item.name}} </p>
                </div>
                <div class="p1">
                  <p class="t1">·专家：</p>
                  <p class="tex" v-if="(expertTypes && expertTypes.length>0) && item.expertType">
                    {{$selectDict(expertTypes, item.expertType).dictLabel}}
                  </p>
                </div>
                <div class="p1">
                  <p class="t1">·擅长领域：</p>
                  <p class="tex">{{lndustryField(item.lndustryField)}}</p>
                </div>
            </div>
            <div class="it-img">
              <img v-if="item.headUrl" :src="item.headUrl" >
				      <img v-else src="@/assets/image/finance/txico.png" >
            </div>
        </div>
      </div>
      <div class="btn-bottom">
        <Buttons @goBack="goBack()" @none="''" @apply="apply" :buttons="buttons"></Buttons>
      </div>
    </div>
  </div>
</template>

<script>
import Breadcrumb from "@/components/breadcrumb";
import { request, uploadFile } from "@/utils/request.js";
import config from "@/utils/config.js";
import {checkLogin,relogin} from '@/utils/util.js'

import { getTalentList, getWorkerDetail } from '@/common/api/help'

export default {
  name: "helpHumanDetail",
  meta: {
    name: "人员简历详情页",
  },
  components: { Breadcrumb },
  data() {
    return {
      promotionList: [],
      expertTypes: [],
      industryFields: [],
      crumbs: [
        // {label: "门户首页",value: "index",},
        {label: "人才服务",value: "help",},
        {label: "人员简历列表",value: "helpHumanList",},
        {label: "人员简历",value: "",choose: true,},
      ],
      human: {},
      loading: false, //加载状态
      genderLsit: [],
      workerEducationLsit: [],
      experience: []
    };
  },
  computed: {
    buttons(){
      let btnStyle = [{text:"返回",type:"normal",size:"l",method:"goBack"}]
      if(this.human.status == 2){
        btnStyle.push({text:"已通过",type:"success",size:"l",method:"none"})
      }else if(this.human.status == 3){
        btnStyle.push({text:"已拒绝",type:"success",size:"l",method:"none"})
      }else if(this.human.status == 1){
        btnStyle.push({text:"已申请过",type:"success",size:"l",method:"none"})
      }else if(this.human.status == 0){
        btnStyle.push({text:"申请简历",type:"success",size:"l",method:"apply"})
      }
      return btnStyle;
    },
		lndustryField() {
			return function(value){
				let strs = []
        if(value){
          strs = value.split(',')
        }
        let data = []
        if(this.industryFields && this.industryFields.length>0) {
          strs.forEach((el, i) => {
            data.push(this.$selectDict(this.industryFields, el).dictLabel)
          });
          let str = data.join(',')
          return str.length > 30 ? str.substring(0,30) + '...' : str
        }
				
			}
		}
	},
  mounted(){
    this.gettypeList();
    this.loading = true;
    let type = this.$route.query.type
    if(type){
      console.log('type', type)
      this.crumbs = [
        {label: "门户首页",value: "index",},
        {label: "人才服务",value: "help",},
        {label: "人员简历",value: "",choose: true,},
      ]
    }
    this.getWorkerDetail();
    this.getTalentList();
    
    
  },
  // activated() {
  //   this.genderLsit = JSON.parse(localStorage.getItem('genderLsit'))
  //   this.workerEducationLsit = JSON.parse(localStorage.getItem('workerEducationLsit'))
  //   this.loading = true;
  //   this.getWorkerDetail();
  //   this.getTalentList()
    
  // },
  inject: ['showModal'],
  methods: {
    // 字典查询 
    async gettypeList() {
      let api = `gender,worker_education,expert_type,company_industry`;
      // 调用公共方法中的查询字典表
      this.getDictList(this, api).then((res) => {
        this.genderLsit = res.gender;
        this.workerEducationLsit = res.worker_education;
        this.expertTypes = res.expert_type
        this.industryFields = res.company_industry
      });
    },
    // 获取人才列表
		async getTalentList(){
			let data = {
				pageNum: 1,
				pageSize: 3,
			}
			const { code, msg, rows} = await getTalentList(data);
			if(code != '200') return this.$message.warning(msg);
			this.promotionList = rows;
    },
    // 推荐人才跳转到详情页
    toDetail(item, i) {
			// this.swiper.slideTo(i)
			this.$router.push({ name: 'talentRecommendDetail', params: { talent: JSON.stringify(item), isHelp: true,type:1 } });
		},
    // 获取务工人员详情
    async getWorkerDetail(id) {
      const { code, msg, data } = await getWorkerDetail(this.$route.query.id)
      this.loading = false;
      if (code != "200") return this.$message.warning(msg);
      this.human = data;
      this.experience = data.workerExperienceList
    },
    // 点击申请简历
    apply() {
      if(checkLogin(this)){
        let formData = new FormData();
        formData.append("id", this.$route.query.id);
        uploadFile(this, config.api.workerApply, formData).then((res) => {
          if (res.code != "200") return this.$message.warning(res.msg);
          this.showModal('申请简历成功，请耐心等待！', require('@/assets/image/success.png'))
          this.human.status = 1
        });
      }else {
        relogin(this);
      }
      
    },
    goBack: function () {
      // let ns = this
      // ns.$router.go(-1)
      this.$router.back();
      // this.$router.push({ path: 'helpHumanList' });
    },
  },
};
</script>

<style lang="scss" scoped>
.promotion-box{
  display: flex;
  justify-content: space-between;
  .item{
    width: 386px;
    height: 140px;
    box-sizing: border-box;
    border: 10px solid #F1F2F4;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    .it-left{
      width: 270px;
      .p1{
        display: flex;
        margin-top: 10px;
        color: #666666;
        font-size: 14px;
        .t1{
          width: 80px;
          text-align: right;
          margin-right: 10px;
        }
        .tex{
          text-align: left;
          flex: 1;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 95%;
        }
      }
    }
    .it-img{
      width: 35px;
      height: 35px;
      margin-top: 15px;
      margin-right: 15px;
      border-radius: 50%;
      overflow: hidden;
      img{
        width: 100%;
        height: 100%;
      }
    }
  }
}
.layout {
  min-height: 100vh;
  position: relative;
  padding-bottom: 150px;
  box-sizing: border-box;
}
.btn-bottom {
  text-align: center;
  margin: 40px 0 150px;
}
.btn-bottom .cancelBtn {
  display: inline-block;
  font-size: 14px;
  background-color: #f1f2f4;
  color: #045db9;
  /* padding: 10px 46px; */
  text-align: center;
  border-radius: 5px;
  margin-right: 10px;
  width: 120px;
  text-align: center;
  line-height: 40px;
  height: 40px;
}
.btn-bottom .cancelBtn:hover {
  /* border: 1px solid #eeeeee; */
  cursor: pointer;
  box-shadow: 0px 0px 5px #eeeeee;
}
.btn-bottom .sendBtn {
  /* padding: 10px 30px; */
  background-color: #045db9;
  display: inline-block;
  color: #ffffff;
  font-size: 14px;
  border-radius: 5px;
  transition: all 0.2s ease 0s;
  margin-right: 10px;
  width: 120px;
  text-align: center;
  line-height: 40px;
  height: 40px;
}
.btn-bottom .sendBtn:hover {
  box-shadow: 0px 5px 5px #e1e1e1;
  cursor: pointer;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}

.helpHumanDetail {
  width: 1200px;
  margin: 0 auto;
}

.helpHumanDetail .backBtn {
  border: 1px solid #eeeeee;
  white-space: nowrap;
  font-size: 12px;
  height: 30px;
  width: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}

.helpHumanDetail .backBtn:hover {
  cursor: pointer;
  box-shadow: 0px 0px 5px #eeeeee;
}

.helpHumanDetail .topDiv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}

.helpHumanDetail .topDiv .msgDiv {
  font-size: 24px;
  font-weight: bold;
}

.helpHumanDetail .title {
  font-size: 20px;
  font-weight: bold;
  text-align: left;
  color: #045db9;
  border-bottom: 2px solid #045db9;
  padding: 10px 10px 10px 0;
  margin-top: 10px;
  margin-bottom: 20px;
}

.helpHumanDetail .tableDiv {
  border: 1px solid #eeeeee;
  color: #666666;
}

.helpHumanDetail .tableDiv.desc {
  border: 1px solid #eeeeee;
  color: #666666;
  padding: 20px;
  font-size: 14px;
  text-align: left;
  margin-bottom: 38px;
}

.helpHumanDetail .tableDiv .rowDiv {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #eeeeee;
  font-size: 13px;
}

.helpHumanDetail .tableDiv .rowDiv .keyDiv {
  text-align: left;
  background-color: #f4f4f4;
  padding: 10px;
  width: 110px;
}

.helpHumanDetail .tableDiv .rowDiv .valueDiv {
  text-align: left;
  padding: 10px;
  width: 349px;
}
.helpHumanDetail .tableDiv .rowDiv .valueDivFull {
  text-align: left;
  padding: 10px;
  word-break: break-all;
  flex: 1;
}
</style>
